package model.protocal
{
	import model.context.DeviceMonitorContext;
	import model.protocal.base.IProtocol;
	
	import mx.logging.ILogger;
	
	import utils.LogUtil;

	/***
	 *  文件名: DeviceProtocal.as
	 *  简介: 获取设备协议
	 *  参考：?action=interface-getMemberDevices&id[]=185&id[]=195 
	 *  作者:  kant
	 *  时间:  Dec 3, 2012 10:37:04 PM
	 *
	 **/
	public class DeviceProtocal implements IProtocol
	{
		protected var BASE_CMD_STR : String = "?action=interface-getMemberDevices";
		private var context:DeviceMonitorContext;
		public static var NAME : String = "DeviceProtocal.as";
		private var logger:ILogger =  LogUtil.getInst().getLogger( NAME );
		
		public function DeviceProtocal(context:DeviceMonitorContext)
		{
			this.context = context;
			if ( context != null )
			{
				addDeviceIdsByList(this.context.getDevIdList());
				
				BASE_CMD_STR = Global.SERVER_DEVICE_URL + BASE_CMD_STR;
			}
		}
		
		protected function getBaseProtocalRootUrl():String
		{
				return Global.SERVER_DEVICE_URL + "?action=";
		}
		
		/**
		 *  添加设备
		 *  &id[]=xx&id[]=xx
		 **/
		private  function addDeviceById(id:String):void
		{
			if ( id != null ) 
			{
				BASE_CMD_STR += "&id[]=" + id;
			}
		}
		
		/**
		 *  通过列表来添加
		 * */
		private function addDeviceIdsByList(list:Array):void{
			if(list != null && list.length > 0 )
			{
				for each(var id:String in list) {
					addDeviceById(id);		
				}
			}
		}
		
		/**
		 *  返回协议
		 **/
		public function getProtocal():String
		{
			return BASE_CMD_STR;
		}
		
		/**
		 *  获取协议串
		 **/
		public function getProtocalString():String
		{
			return getProtocal();
		}
		
		/**
		 * 返回处理
		 * event:Object
		 **/
		public function  onResponseHandler(evt:Object):void
		{
			logger.info("消息返回...");
		}
	}
}